<template>
	<view>

		<view v-if="orderList.length > 0">

			<view class="item" style="padding: 0;" v-for="(item, index) in orderList" :key="index">

				<view class="title-wrap">

					<text class="title" v-if='item.rentType === 1'>经租</text>
					<text class="title" v-if='item.rentType === 2'>以租代购</text>
					<text class="title" v-if='item.rentType === 3'>展示车</text>
					<text class="title" v-if='item.rentType === 4'>试驾车</text>
					<text class="title" v-if='item.rentType === 5'>融租</text>
					<text class="title" v-if='item.rentType === 6'>直购</text>

					<view class="title-warn">
						{{ item.flowStatusName }}
					</view>
				</view>

				<u-line color="#efefef" dashed margin="0 0 15px"></u-line>

				<view class="text-line">
					<text class="text-name">车辆订单号:</text>
					<text class="text-value">{{filterNull(item.orderCarCode)}}</text>
				</view>


				<view class="text-line" v-if="item.rentType!=6">
					<text class="text-name">租期:</text>
					<text class="text-value"
						style="flex-grow: 0;">{{filterNull(item.timeStartRent)}}至{{filterNull(item.timeFinishRent)}}</text>

					<text class="tenacy">{{filterNull(item.tenancy)}}期</text>
				</view>

				<view class="text-line">
					<text class="text-name">车牌号:</text>
					<text class="text-value">{{filterNull(item.carNo)}}</text>
				</view>

				<view class="text-line">
					<text class="text-name">品牌/车系/车型:</text>
					<text
						class="text-value">{{filterNull(item.brandName)}}/{{filterNull(item.seriesName)}}/{{filterNull(item.modelName)}}</text>
				</view>


				<view class="text-line" v-if="item.rentType==5">
					<text class="text-name">金融公司:</text>
					<text class="text-value">{{filterNull(item.financeCompanyName)}}</text>
				</view>

				<view class="fee-list" @click.stop="itemClick(item)">
					
					<view class="flex">
						<view style="display: inline-flex;" v-for="(childitem, childindex) in item.moneyPlanList"
							:key="childitem.moneyDesc">
							<text class="text-name" style="margin-left: 20upx;">{{childitem.moneyDesc}}:</text>
							<text class="text-value">￥{{childitem.moneyAmount}}</text>
						</view>
					</view>
					
					<u-icon name="arrow-right"></u-icon>
				</view>

				<view class="own-money" v-if="item.uncollectedAmountDesc">
					{{filterNull(item.uncollectedAmountDesc)}}
				</view>

				<view class="title-wrap" style="justify-content: flex-end;margin-bottom: 10upx;">

					<view class="btn-detail" @click.stop="itemClick(item)">
						详情
					</view>

					<view v-if="isEnv!=3 && item.uncollectedAmount>0" class="btn-detail" style="background-color: #E04B28;"
						@click.stop="itemClick(item)">
						立即支付
					</view>
				</view>

				<!-- 欠款提醒 -->
				<view class="own-money wran" v-if='item.receivablesDesc'>{{item.receivablesDesc}}</view>
				<!-- 替换车提醒 -->
				<view class="own-money wran" v-if='item.swappedOrderCarDesc'>{{item.swappedOrderCarDesc}}</view>
				<!-- 被替换车提醒 -->
				<view class="own-money wran" v-if='item.swopOrderCarDesc'>{{item.swopOrderCarDesc}}</view>
				<!-- 备用车 -->
				<view class="own-money wran" v-if='item.spareCarDesc'>{{item.spareCarDesc}}</view>

			</view>

			<u-loadmore v-if="pageNo>2" :status="loadingStatus" @loadmore="clickloadmore"></u-loadmore>
		</view>

		<no-data v-else></no-data>

	</view>
</template>

<script>
	import {
		ordercarlist,
		commonenv
	} from '../../../common/api.js';

	export default {
		data() {
			return {
				isEnv: 0,
				pageNo: 1,
				loadingStatus: 'loading',
				orderList: []
			}
		},

		onShow() {
			this.pageNo = 1;
			this.getData();
			this.getEnv();
		},

		methods: {
			getEnv(){
				commonenv().then(res=>{
					this.isEnv = res;
				})
			},
			getData() {
				ordercarlist({
					params: {
						pageNo: this.pageNo
					}
				}).then(res => {
					if (this.pageNo == 1) {
						this.orderList = [];
						this.pageNo++;
						// uni.stopPullDownRefresh();

						this.loadingStatus = 'loadmore';
					} else {
						if (!uni.$u.test.isEmpty(res)) {
							this.pageNo++;

							this.loadingStatus = 'loadmore';
						} else {

							this.loadingStatus = 'nomore';
						}
					}

					if (!uni.$u.test.isEmpty(res)) {
						this.orderList = this.orderList.concat(res);
					}
					
				})
			},

			// pay(item){
			// 	uni.showLoading({
			// 		title: '加载中...',
			// 	})
			// 	uni.$u.http.post('app/pay', {
			// 		type: 1, //{2订单1缴费}
			// 		receivablesId: this.receivablesId, // 缴费id
			// 		orderCarId: '' // 订单id
			// 	}).then(res => {
			// 		console.log(res)
			// 		uni.hideLoading()
			// 		uni.requestPayment({
			// 			timeStamp: res.timeStamp,
			// 			nonceStr: res.nonceStr,
			// 			package: res.package,
			// 			signType: res.signType,
			// 			paySign: res.paySign,
			// 			success(res) {
			// 				console.log(res);
			// 				// uni.navigateBack()
			// 				this.pageNo = 1;
			// 				this.getData();
			// 			},
			// 			fail(res) {
			// 				uni.hideLoading()
			// 				uni.showToast({
			// 					title: '支付取消',
			// 					icon: 'none'
			// 				})
			// 			}
			// 		});
			// 	});
			// },

			itemClick(item) {
				uni.navigateTo({
					url: './car-orderdetail?id=' + item.orderCarId
				})
			},

			clickloadmore() {
				this.getData();
				this.showloading = true;
				this.loadingStatus = 'loading';
			},


		},
		onPullDownRefresh() {
			this.pageNo = 1;
			this.getData();
		},

		onReachBottom() {
			console.log('到底了');

			this.getData();
			this.showloading = true;
			this.loadingStatus = 'loading';
		}

	}
</script>

<style lang="scss" scoped>
	.title-wrap {
		display: flex;
		align-items: center;
		justify-content: space-between;
		margin: 0;
	}

	.title {
		width: 100%;
		height: 80upx;
		line-height: 80upx;
		font-size: 32upx;
		margin-left: 20upx;
		color: $black33;
		font-weight: bold;
	}

	.title-warn {
		color: $white;
		background-color: $yellowffc;
		border-radius: 90upx 0 0 90upx;
		white-space: nowrap;
		text-align: center;
		font-size: 24upx;
		line-height: 46upx;
		padding: 0 10upx;
	}

	.tenacy {
		font-size: 24upx;
		color: $yellowffc;
		padding: 3upx 8upx;
		border-radius: 8upx;
		border: 2upx solid $yellowffc;
		margin-left: 20upx;
	}

	.fee-list {
		@include flex;
		align-items: center;
		justify-content: flex-end;
		margin-right: 20upx;

		text {
			color: $black33;
			font-size: 28upx;
			font-weight: bold;
		}


	}

	.own-money {
		color: $rede9;
		font-size: 28upx;
		align-self: flex-end;
		margin: 20upx 20upx 0 0;
	}

	.wran {
		color: $yellowffc;
		margin: 0 20upx 40upx 0;
	}
</style>
